home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ftpser1a / fndfile.bas < prev    next >
BASIC Source File  |  1999-08-24  |  3KB  |  82 lines

  1. Attribute VB_Name = "FndFile"
  2. Option Explicit
  3.  
  4. Public Const MAX_PATH As Long = 260
  5. Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
  6. Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
  7. Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
  8. Public Const FILE_ATTRIBUTE_HIDDEN = &H2
  9. Public Const FILE_ATTRIBUTE_NORMAL = &H80
  10. Public Const FILE_ATTRIBUTE_READONLY = &H1
  11. Public Const FILE_ATTRIBUTE_SYSTEM = &H4
  12. Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
  13.  
  14. Type FileTime
  15.   dwLowDateTime As Long
  16.   dwHighDateTime As Long
  17. End Type
  18.  
  19. Public Type WIN32_FIND_DATA
  20.   dwFileAttributes As Long
  21.   ftCreationTime As FileTime
  22.   ftLastAccessTime As FileTime
  23.   ftLastWriteTime As FileTime
  24.   nFileSizeHigh As Long
  25.   nFileSizeLow As Long
  26.   dwReserved0 As Long
  27.   dwReserved1 As Long
  28.   cFileName As String * MAX_PATH
  29.   cAlternate As String * 14
  30. End Type
  31.  
  32. Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  33. Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  34. Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  35. Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  36. Public Declare Function SearchPath Lib "kernel32" Alias "SearchPathA" (ByVal lpPath As String, ByVal lpFileName As String, ByVal lpExtension As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
  37.     
  38. Public Function FindFile(ByVal Filename As String, ByVal Path As String) As String
  39. Dim hFile As Long, result As Long
  40. Dim ts As String, szPath As String
  41. Dim WFD As WIN32_FIND_DATA
  42. Dim szPath2 As String, szFilename As String
  43. Dim dwBufferLen As Long, szBuffer As String, lpFilePart As String
  44.   szPath = GetRDP(Path) & "*.*" & Chr$(0)
  45.   szPath2 = Path & Chr$(0)
  46.   szFilename = Filename & Chr$(0)
  47.   szBuffer = String$(MAX_PATH, 0)
  48.   dwBufferLen = Len(szBuffer)
  49.   result = SearchPath(szPath2, szFilename, vbNullString, dwBufferLen, szBuffer, lpFilePart)
  50.   If result Then
  51.     FindFile = StripNull(szBuffer)
  52.     Exit Function
  53.   End If
  54.   hFile = FindFirstFile(szPath, WFD)  'Start asking windows for files.
  55.   Do
  56.     If (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
  57.       ts = StripNull(WFD.cFileName)
  58.       If ts <> "." Then
  59.         FindFolder.FolderList.AddItem (ts)
  60.       End If
  61.     End If
  62.     WFD.cFileName = ""
  63.     result = FindNextFile(hFile, WFD)
  64.   Loop Until result = 0
  65.   FindClose hFile
  66. End Function
  67.  
  68. Public Function StripNull(ByVal WhatStr As String) As String
  69.   If InStr(WhatStr, Chr$(0)) > 0 Then
  70.     StripNull = Left$(WhatStr, InStr(WhatStr, Chr$(0)) - 1)
  71.   Else
  72.     StripNull = WhatStr
  73.   End If
  74. End Function
  75.  
  76. Public Function GetRDP(ByVal sPath As String) As String
  77. 'Adds a backslash on the end of a path, if required.
  78.   If sPath = "" Then Exit Function
  79.   If Right$(sPath, 1) = "\" Then GetRDP = sPath: Exit Function
  80.     GetRDP = sPath & "\"
  81. End Function
  82.